<template>
  <van-nav-bar title="个人信息" left-text="返回" left-arrow @click-left="onClickLeft" />

  <div>
    <van-cell-group inset>
      <van-field v-model="user.nickname" label="昵称" placeholder="请输入用户名" />
      <van-field v-model="user.gender" label="性别" placeholder="请选择你的性别" />
      <van-field v-model="user.age" label="年龄" placeholder="请输入你的年龄" />
      <van-field v-model="user.identity" label="职业" placeholder="请选择你的职业" readonly />
      <van-field v-model="user.createTime" label="电话" placeholder="请输入联系方式" />
    </van-cell-group>
    <van-button type="primary" class="sure" @click="yes()">保存</van-button>
  </div>
</template>
<script>
import { updatereq, inforeq } from '../../api/requies'

export default {
  methods: {
    onClickLeft() {
      this.$router.back()
    },
    yes() {
      const id = localStorage.getItem('id')
      updatereq(id, this.user.age, this.user.gender, this.user.nickname).then((r) => {
        console.log(r.data)
        // eslint-disable-next-line no-undef
        showSuccessToast(r.data.message)
        this.$router.back()
      })
    },
    loadlist() {
      const id = localStorage.getItem('id')
      inforeq(id).then((r) => {
        console.log(r.data)
        this.user = r.data.info
      })
    }
  },
  data() {
    return {
      user: {}
    }
  },
  mounted() {
    this.loadlist()
  }
}
</script>
<style lang="scss">
.sure {
  width: 100px;
  position: absolute;
  left: 38%;
  top: 60%;
}
</style>
